package com.newer.textdbnotepad

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.newer.textdbnotepad.sdk.NoteInfo
import com.newer.textdbnotepad.sdk.NoteRepository
import com.newer.textdbnotepad.sdk.SessionManager
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(private val noteRepository: NoteRepository) : ViewModel() {

    private val _listOfNotes = MutableLiveData<List<NoteInfo>>(emptyList())
    val listOfNotes: LiveData<List<NoteInfo>> = _listOfNotes

    fun getAllNotes() {
        viewModelScope.launch {
            _listOfNotes.value = noteRepository.getUser(SessionManager.getCurrentUserKey()!!)?.notes.orEmpty()
        }

    }

}